# coding:utf8
from __future__ import unicode_literals

from django.db import models

# Create your models here.

from myauth.models import MyGroup,MyUser,PlatForm
from django.db import models
from cmdb.models import Server

from  database.models import  Mysql,Mongodb

class Game( models.Model):
    STATE_CHOICE = ((-1, '未安装'),(0, '已经安装'),(1, '安装中'),(2, '已经合服'),)
    PHONE_TYPE_CHOICES =(
            ('android', '安卓'),
            ('ios', 'ios'),
            ('iosyy', 'ios越狱'),
            )
    GAME_TYPE_CHOICES =(
            ('s', '正式服'),
            ('t', '测试服'),
            ('d', '开发服'),
            )

    name = models.CharField('游戏名', unique=True, max_length=100)
    platform = models.ForeignKey(PlatForm, verbose_name='平台', help_text='平台和代理是不一样的，一个代理旗下可能有多个平台')
    version= models.CharField('游戏版本号',  max_length=100)
    server = models.ForeignKey(Server, verbose_name='服务端代码存放')
    mysql = models.ForeignKey(Mysql, verbose_name='mysql主数据库', help_text='只能指定主数据库',
            limit_choices_to={'mysql_type': 'master'})
    state = models.IntegerField(verbose_name='安装状态', help_text="是否安装合服等", choices=STATE_CHOICE, default='-1')
    phone_type = models.CharField('手机类型', help_text='手机平台的类型', choices=PHONE_TYPE_CHOICES, default='android', max_length=250)
    game_type = models.CharField('游戏类型', help_text='游戏是测试服、正式服等', choices=GAME_TYPE_CHOICES, default='s', max_length=250)
    open_date = models.DateTimeField('开服时间', null=True,blank=True, help_text='如果不设置，自动设定为当前时间')
    game_id = models.IntegerField('平台游戏服ID', help_text='每个平台的游戏服ID都是独立的')
    game_user=models.CharField(verbose_name='游戏用户名',null=True, max_length=30, blank=True)
    create_date = models.DateTimeField('创建时间', auto_now_add=True)
    update_date = models.DateTimeField('修改时间', auto_now_add=True)
    class Meta:
        ordering = ['game_id']
        #order_with_respect_to
        # unique_together = (
        #         ('platform', 'game_id', 'game_type'),
        #         ('server'),
        #         )

    def __str__(self):
        return self.name





class Game_Update_log(models.Model):
    name = models.CharField('游戏名', max_length=100)
    game_user=models.CharField('游戏用户名',max_length=30,default='')
    server_ip=models.GenericIPAddressField('服务器Ip',default='')
    oprate_user=models.CharField('操作用户',max_length=100,default='')
    update_time=models.DateTimeField('更新时间', auto_now_add=True)
    update_action= models.CharField('更新步骤', max_length=100)
    update_result= models.CharField('更新结果', max_length=100)
    update_more_info=models.TextField('详细日志')

    def __str__(self):
        return self.name



